class Solution
{
public:
    bool canArrange(vector<int> &arr, int k)
    {
        unordered_map<int, int> modCount;
        for (int num : arr)
        {
            int mod = (num % k + k) % k;
            ++modCount[mod];
        }
        if (modCount[0] & 1)
        {
            return false;
        }
        modCount.erase(0);
        while (!modCount.empty())
        {
            int mod = modCount.begin()->first;
            if (modCount[mod] != modCount[k - mod])
            {
                return false;
            }
            modCount.erase(mod);
            modCount.erase(k - mod);
        }
        return true;
    }
};